﻿@model IEnumerable<QBWeb.Models.QuestionFolder.QuestionTb>
@{
    ViewBag.Title = "_Card2";
    Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_LayoutToWord.cshtml";
}

<div class="row" style="margin:0 10px 10px 10px;">
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-2">
            </div>
            <div class="col-md-8">

            </div>
            <div class="col-md-2">
                <button type="submit" class="layui-btn layui-btn-normal pull-right" id="btn" onclick="btnShow()"><span class="glyphicon glyphicon-plus"></span>&nbsp;本地导入</button>
            </div>
        </div>

    </div>
</div>
<table class="table">
    <tr>
        <th>
            ID
        </th>
        <th>
            题干
        </th>
        <th>
            题型
        </th>
        <th>
            关键词
        </th>
        <th>
            答案解析
        </th>
        <th>
            难度
        </th>
        <th>
            备注
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QuestName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QuestTypeTbId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Keywords)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QuestAnalysis)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QuestLevel)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.QuestNotes)
            </td>
        </tr>
    }

</table>

<div class="modal fade" id="firstModal" data-backdrop="static">
    <div class="modal-dialog modal-lg" style="width: 90%;">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="font-size:30px">×</span></button>

                <button class="modal-title btn btn-primary" type="button" onclick="btnWakeFile()">导入Word文档</button>

            </div>

            <!-- 模态框主体 -->
            <div class="modal-body" id="questions">

                <div class="layui-row" style="">
                    <div class="layui-col-md6" style="border-right: solid 1px lightgray;">
                        <div id="leftRef" style="height: 540px;">
                            <textarea class="layui-textarea textareaClass" name="textData" form="WordForm2"></textarea>
                        </div>
                    </div>
                    <div class="layui-col-md6" style=" height: 540px; overflow:auto; word-wrap: break-word;padding-left:5px" id="rightRef">
                        <!-- 要更新的内容 Ref=Refresh-->

                    </div>
                </div>

            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer " style="text-align: center">
                <button type="button" class="btn btn-success" onclick="btnSubmit(NA2)">识别</button>
                @*<button type="button" class="btn btn-primary" onclick="btnSubmit(NA3)">确定导入</button>*@
                <a href="javascipt:void(0)" class="btn btn-primary" id="btn2">确定导入</a>
                <button type="button" class="btn btn-default" data-dismiss="modal" aria-label="Close">取消</button>
            </div>

        </div>
    </div>
</div>

@using (Ajax.BeginForm("Upload", "WordImport", null,
    new AjaxOptions()
    {
        HttpMethod = "Post",
        InsertionMode = InsertionMode.Replace,
        Confirm = "确定导入？",
        UpdateTargetId = "leftRef",
        OnBegin = "oS()",
        OnSuccess = "oE()"
    },
    new { @enctype = "multipart/form-data", id = "WordForm" }))
{
    <input type="file" style="display:none" name="wordFile" class="btn-default" id="fileWord" onchange="btnSubmit(NA)" form="WordForm" />
    <input type="submit" id="NA" style="display:none " />
}
@using (Ajax.BeginForm("Recognition", "WordImport", null,
    new AjaxOptions()
    {
        HttpMethod = "Post",
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "rightRef",
        OnBegin = "oS()",
        OnSuccess = "oE2()"
    },
    new { id = "WordForm2" }))
{
    <input type="submit" id="NA2" style="display:none " />
}

<script>
    function btnSubmit(id) {

        $(eval(id)).click();  //小bug，不能直接触发ajax表单，只能这样
    }
    function btnShow() {
        $("#btn2").attr("href", "javascript:void(0);");
        $('#firstModal').modal('show');
    }
    function goOut() {
        history.go(-1);
    }
    function btnWakeFile() {
        $('#fileWord').click();
    }

    function btnHide() {
        $('#firstModal').modal('hide');
    }

    function oS() {

        layer.msg('请稍等..', {
            icon: 16
            , shade: 0.3
            , time: 10000
        });
    }

    function oE() {
        layer.closeAll();
    }
    function oE2() {
        layer.closeAll();
        $("#btn2").attr("href", "/WordImport/SaveResult");
        $("#btn2").attr("onclick", "oS()");
    }
</script>